﻿/*
#**************************************************************************
#  openSIS is a student information system for public and non-public 
#  schools from Open Solutions for Education, Inc. web: www.os4ed.com
#
#  openSIS is  web-based, open source, and comes packed with features that 
#  include student demographic info, scheduling, grade book, attendance, 
#  report cards, eligibility, transcripts, parent portal, 
#  student portal and more.   
#
#  Visit the openSIS web site at http://www.opensis.com to learn more.
#  If you have question regarding this system or the license, please send 
#  an email to info@os4ed.com.
#
#  This program is released under the terms of the GNU General Public License  
#  as  published by the Free Software Foundation, version 2 of the License. 
#  See license.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#**************************************************************************** 

*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using OpenSISInstall;
using AjaxControlToolkit;
using OpenSIS.OpenSISWCFServiceReference;
using OSISDynamicTranslation;

namespace OpenSIS.Staff
{
    public partial class StaffInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string sCulture = Session["MLCulture"].ToString();
            //StaffBL STABL = new StaffBL();
            // Session["StaffId"] = STABL.StaffId;
            // Session["SchoolID"] = STABL.HomeSchoolId;
            // Session["DirectView"] = "DV";

            if (Session["DirectView"] != null)
            {
                if (Session["DirectView"].ToString() == "DV")
                {
                    mvMain.ActiveViewIndex = 1;
                    hdnStfId.Value = Session["StaffId"].ToString();
                    int SchoolId = Convert.ToInt32(Session["SchoolID"]);
                    OpenSISWCFServiceStaffClient STClient = new OpenSISWCFServiceStaffClient();
                    DataTable dt = STClient.PopulateStaffBySchoolID(SchoolId, "", "", "");
                    STClient.Close();
                    int staffs = dt.Rows.Count;
                    lblStaffNo.Text = staffs.ToString();
                    lblTotalStaffOfSchool.Text = (dt.Rows.Count).ToString();
                    if (lblStaffNo.Text == lblTotalStaffOfSchool.Text)
                    {
                        lbtnLastStaff.Enabled = false;
                        lbtnNextStaff.Enabled = false;
                    }
                    if (lblStaffNo.Text == "1")
                    {
                        lbtnPreviousStaff.Enabled = false;
                        lbtnFirstStaff.Enabled = false;
                    }
                    PopulateStaffDetails();
                    Session["DirectView"] = null;
                }
            }

            SISInstall SISInstall = new SISInstall();
            OpenSISWCFServiceInstallationClient OSISinstallClient = new OpenSISWCFServiceInstallationClient();
            DataTable dtDateFormat = OSISinstallClient.getdateformat();
            OSISinstallClient.Close();
            if (dtDateFormat.Rows.Count > 0)
            {
                SISInstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
            }
            if (!Page.IsPostBack)
            {
                //populatecontrols();
                PopulateStaffListGrid();
                PopulateCategoryTree();
                tvCategories.Nodes[0].Select();
                lblCatName.Text = "<div class='heading_bevelline'>" + tvCategories.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
            }
            ibtnEdit.Attributes.Add("onclick", "return GridCheckBoxSelection('" + sCulture + "')");
            ibtnView.Attributes.Add("onclick", "return GridCheckBoxSelection('" + sCulture + "')");
        }

        protected void PopulateStaffListGrid()
        {
            try
            {
                int SchoolId = Convert.ToInt32(Session["SchoolId"]);
                OpenSISWCFServiceStaffClient STClientGrid = new OpenSISWCFServiceStaffClient();
                DataTable dt = STClientGrid.PopulateStaffBySchoolID(SchoolId, "", "", "");
                STClientGrid.Close();
                gvStaff.DataSource = dt;
                gvStaff.DataBind();
            }
            catch
            {
            }
            finally
            {
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                int SchoolId = Convert.ToInt32(Session["SchoolId"]);
                OpenSISWCFServiceStaffClient STClientGridP = new OpenSISWCFServiceStaffClient();
                DataTable dt = STClientGridP.PopulateStaffBySchoolID(SchoolId,txtFName.Text,txtLName.Text,txtUsername.Text);
                STClientGridP.Close();
                gvStaff.DataSource = dt;
                gvStaff.DataBind();
            }
            catch
            {
            }
            finally
            {
            }
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            //Function Func = new Function();
            //try
            //{
            //    Func.ResetFormControlValues(this.Page);
            //}
            //catch { }
            //finally
            //{
            //    Func = null;
            //}
        }

        protected void gvStaff_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            if (e.CommandName == "ShowStaffInfo")
            {
                string staffid = e.CommandArgument.ToString().Split("_".ToCharArray())[1];
                hdnStfId.Value = staffid;
                int StaffId = Convert.ToInt32(staffid);
                Session["StaffID"] = StaffId;
                int SchoolId = Convert.ToInt32(Session["SchoolID"]);
                //StdInfo.CatId = 1;
                PopulateStaffDetails();
                tvCategories.Nodes[0].Select();
                lblCatName.Text = "<div class='heading_bevelline'>" + tvCategories.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
                ////tvStudent360.Nodes[1].Selected = true;
                ////PopulateSummaryFields();
                int itemindex = Int32.Parse(e.CommandArgument.ToString().Split("_".ToCharArray())[0]);
                lblStaffNo.Text = (itemindex + 1).ToString();
                lblTotalStaffOfSchool.Text = (gvStaff.Rows.Count).ToString();
                if (lblStaffNo.Text == lblTotalStaffOfSchool.Text)
                {
                    lbtnLastStaff.Enabled = false;
                    lbtnNextStaff.Enabled = false;
                }
                if (lblStaffNo.Text == "1")
                {
                    lbtnPreviousStaff.Enabled = false;
                    lbtnFirstStaff.Enabled = false;
                }
                mvMain.ActiveViewIndex = 1;
            }
        }

        protected void gvStaff_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                LinkButton lbtnStdSchId = new LinkButton();
                lbtnStdSchId = (LinkButton)e.Row.FindControl("lbtnStdSchId");
                lbtnStdSchId.CommandArgument = e.Row.RowIndex.ToString() + "_" + DataBinder.Eval(e.Row.DataItem, "staffid");
            }
        }

        public void populatecontrols()
        {
            //StaffBL STABL = new StaffBL();
            //try
            //{
            //    //STABL.PopulateAccessRoles(ref ddlProfile);
            //}
            //catch
            //{
            //}  
        }

        public void PopulateCategoryTree()
        {
            DynamicTranslation DTL = new DynamicTranslation();
            string langto = Session["MLUICulture"].ToString();
            try
            {
                tvCategories.Nodes.Clear();
                TreeNode TreeNodeDemoInfo = new TreeNode();
                string s = "Demographic Information";
                string t = DTL.Translate(s, "en", langto);
                TreeNodeDemoInfo.Text = t + "&nbsp;&nbsp;&nbsp;&nbsp;";
                TreeNodeDemoInfo.Value = Convert.ToString("0");
                tvCategories.Nodes.Add(TreeNodeDemoInfo);

                s = "Address and Contact";
                t = DTL.Translate(s, "en", langto);
                TreeNode TreeNodeAddCont = new TreeNode();
                TreeNodeAddCont.Text = t + "&nbsp;&nbsp;&nbsp;&nbsp;";
                TreeNodeAddCont.Value = Convert.ToString("1");
                tvCategories.Nodes.Add(TreeNodeAddCont);

                s = "School Information";
                t = DTL.Translate(s, "en", langto);
                TreeNode TreeNodeSchoolInfo = new TreeNode();
                TreeNodeSchoolInfo.Text = t + "&nbsp;&nbsp;&nbsp;&nbsp;";
                TreeNodeSchoolInfo.Value = Convert.ToString("2");
                tvCategories.Nodes.Add(TreeNodeSchoolInfo);

                s = "Certification Information";
                t = DTL.Translate(s, "en", langto);
                TreeNode TreeNodeCertificate = new TreeNode();
                TreeNodeCertificate.Text = t + "&nbsp;&nbsp;&nbsp;&nbsp;";
                TreeNodeCertificate.Value = Convert.ToString("3");
                tvCategories.Nodes.Add(TreeNodeCertificate);
                tvCategories.ExpandAll();
            }
            catch
            {

            }
        }

        protected void tvCategories_SelectedNodeChanged(object sender, EventArgs e)
        {
            try
            {
                string CatValue = tvCategories.SelectedNode.Value;
                mvCategories.ActiveViewIndex = Convert.ToInt32(CatValue);
                lblCatName.Text = "<div class='heading_bevelline'>" + tvCategories.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
                int category = Convert.ToInt32(tvCategories.SelectedNode.Value);
                hdnCatId.Value = Convert.ToString(category);
            }
            catch
            {
            }
        }

        protected void lbtnNextStaff_Click(object sender, EventArgs e)
        {
            try
            {
                lbtnFirstStaff.Enabled = true;
                lbtnPreviousStaff.Enabled = true;
                //DropDownList ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                int SchoolId = Convert.ToInt32(Session["SchoolID"]);
                int StaffId = Convert.ToInt32(Session["StaffId"]);
               
                OpenSISWCFServiceStaffClient OSClientSt = new OpenSISWCFServiceStaffClient();
                DataTable dt = OSClientSt.GetNextStaffId(StaffId, SchoolId);
                OSClientSt.Close();
                hdnStfId.Value = dt.Rows[0]["stf_id"].ToString();
                int staffno = Convert.ToInt32(lblStaffNo.Text);
                lblStaffNo.Text = Convert.ToString(staffno + 1);
                Session["StaffId"] = Convert.ToInt32(hdnStfId.Value);
                PopulateStaffDetails();
                tvCategories.Nodes[0].Selected = true;
                lblCatName.Text = "<div class='heading_bevelline'>" + tvCategories.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
                if ((Convert.ToInt32(lblStaffNo.Text)) == (Convert.ToInt32(lblTotalStaffOfSchool.Text)))
                {
                    lbtnNextStaff.Enabled = false;
                    lbtnLastStaff.Enabled = false;
                }
                mvCategories.ActiveViewIndex = 0;
                mvMain.ActiveViewIndex = 1;
            }
            catch
            {
            }
        }

        protected void lbtnPreviousStaff_Click(object sender, EventArgs e)
        {            
            try
            {
                lbtnNextStaff.Enabled = true;
                lbtnLastStaff.Enabled = true;
                int SchoolId = Convert.ToInt32(Session["SchoolID"]);
                int StaffId = Convert.ToInt32(Session["StaffId"]);
                OpenSISWCFServiceStaffClient OSClientSt1 = new OpenSISWCFServiceStaffClient();
                DataSet dt = OSClientSt1.GetPreviousStaffId(StaffId,SchoolId);
                OSClientSt1.Close();
                hdnStfId.Value = dt.Tables[0].Rows[0]["stf_id"].ToString();
                int studentno = Convert.ToInt32(lblStaffNo.Text);
                lblStaffNo.Text = Convert.ToString(studentno - 1);
                Session["StaffId"] = Convert.ToInt32(hdnStfId.Value);
                // StdInfo.CatId = 1;
                PopulateStaffDetails();
                tvCategories.Nodes[0].Selected = true;
                lblCatName.Text = "<div class='heading_bevelline'>" + tvCategories.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
                // PopulateSummaryFields();
                if (lblStaffNo.Text == "1")
                {
                    lbtnPreviousStaff.Enabled = false;
                    lbtnFirstStaff.Enabled = false;
                }
                mvCategories.ActiveViewIndex = 0;
                mvMain.ActiveViewIndex = 1;
            }
            catch
            {
            }
        }

        protected void lbtnFirstStaff_Click(object sender, EventArgs e)
        {
            
            try
            {
                lbtnLastStaff.Enabled = true;
                if (lblTotalStaffOfSchool.Text != "1")
                {
                    lbtnNextStaff.Enabled = true;
                }
                else
                {
                    lbtnNextStaff.Enabled = false;
                }

                int SchoolId = Convert.ToInt32(Session["SchoolID"]);

                OpenSISWCFServiceStaffClient SPClient = new OpenSISWCFServiceStaffClient();
                DataTable dt = SPClient.GetFirstStudentIdBySchoolId(SchoolId);
                SPClient.Close();

                Session["StaffID"] = dt.Rows[0]["stf_id"].ToString();
                
                PopulateStaffDetails();
                tvCategories.Nodes[0].Selected = true;
                lblCatName.Text = "<div class='heading_bevelline'>" + tvCategories.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
                lblStaffNo.Text = "1";
                if (lblStaffNo.Text == "1")
                {
                    lbtnPreviousStaff.Enabled = false;
                }
                lbtnFirstStaff.Enabled = false;
                mvCategories.ActiveViewIndex = 0;
                mvMain.ActiveViewIndex = 1;
            }
            catch
            {
            }
        }

        protected void lbtnLastStaff_Click(object sender, EventArgs e)
        {
           
            try
            {
                lbtnFirstStaff.Enabled = true;
                if (lblTotalStaffOfSchool.Text != "1")
                {
                    lbtnPreviousStaff.Enabled = true;
                }
                else
                {
                    lbtnPreviousStaff.Enabled = false;
                }
                int SchoolId = Convert.ToInt32(Session["SchoolID"]);

                OpenSISWCFServiceStaffClient SPClient2 = new OpenSISWCFServiceStaffClient();
                DataTable dt = SPClient2.GetLastStaffIdBySchoolId(SchoolId);
                SPClient2.Close();

                hdnStfId.Value = dt.Rows[0]["stf_id"].ToString();
                Session["StaffID"] = Convert.ToInt32(hdnStfId.Value);
                //StdInfo.CatId = 1;
                PopulateStaffDetails();
                tvCategories.Nodes[0].Selected = true;
                lblCatName.Text = "<div class='heading_bevelline'>" + tvCategories.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
                lblStaffNo.Text = lblTotalStaffOfSchool.Text;
                lbtnNextStaff.Enabled = false;
                lbtnLastStaff.Enabled = false;
                mvCategories.ActiveViewIndex = 0;
                mvMain.ActiveViewIndex = 1;
            }
            catch
            {
            }
        }

        public void PopulateStaffDetails()
        {
            SISInstall SISinstall = new SISInstall();
            try
            {
                int SchoolId = Convert.ToInt32(Session["SchoolID"]);
                int StaffId = Convert.ToInt32(Session["StaffID"]);
                OpenSISWCFServiceStaffClient SPCClientS = new OpenSISWCFServiceStaffClient();
                DataTable dt = SPCClientS.PopulateStaffdetails(SchoolId, StaffId);
                SPCClientS.Close();
                lblStaffId.Text = dt.Rows[0]["staffidnumber"].ToString().Trim();
                lblAltrntId.Text = dt.Rows[0]["stf_alternate_id"].ToString().Trim();
                int salid = Convert.ToInt32(dt.Rows[0]["stf_salutation"].ToString().Trim());
                switch (salid)
                {
                    case 1: lblSalutation.Text = "Dr.";
                        break;
                    case 2: lblSalutation.Text = "Mr.";
                        break;
                    case 3: lblSalutation.Text = "Ms.";
                        break;
                    case 4: lblSalutation.Text = "Mrs.";
                        break;
                    case 5: lblSalutation.Text = "Rev.";
                        break;
                    case 6: lblSalutation.Text = "Miss.";
                        break;
                }
                lblStaFrstNam.Text = dt.Rows[0]["stf_first_nm"].ToString().Trim();
                lblStaMidlNam.Text = dt.Rows[0]["stf_middle_nm"].ToString().Trim();
                lblStalstNam.Text = dt.Rows[0]["stf_last_nm"].ToString().Trim();
                int suffix = Convert.ToInt32(dt.Rows[0]["stf_suffix"].ToString().Trim());
                switch (suffix)
                {
                    case 1: lblSuffix.Text = "JR.";
                        break;
                    case 2: lblSuffix.Text = "Sr.";
                        break;
                    case 3: lblSuffix.Text = "I";
                        break;
                    case 4: lblSuffix.Text = "II";
                        break;
                    case 5: lblSuffix.Text = "III";
                        break;
                    case 6: lblSuffix.Text = "IV";
                        break;
                }
                lblGender.Text = dt.Rows[0]["gender"].ToString().Trim();
                lblDOB.Text = dt.Rows[0]["stf_dob"].ToString().Trim();
                lblEthnicity.Text = dt.Rows[0]["ethnicity"].ToString().Trim();
                lblLang.Text = dt.Rows[0]["firstlanguage"].ToString().Trim();
                lblSecnLang.Text = dt.Rows[0]["secondlang"].ToString().Trim();
                lblThrdLang.Text = dt.Rows[0]["thirdlang"].ToString().Trim();
                switch (dt.Rows[0]["stf_disability"].ToString().Trim())
                {
                    case "Y": lblDisability.Text = "Yes";
                        break;
                    case "N": lblDisability.Text = "No";
                        break;
                    case "": lblDisability.Text = "";
                        break;
                }
                lblDisDesc.Text = dt.Rows[0]["stf_disability_desc"].ToString().Trim();
                lblAdd1.Text = dt.Rows[0]["stf_addr1_pri"].ToString().Trim();
                lblAdd2.Text = dt.Rows[0]["stf_addr2_pri"].ToString().Trim();
                lblCity.Text = dt.Rows[0]["stf_city_pri"].ToString().Trim();
                lblState.Text = dt.Rows[0]["primarystate"].ToString().Trim();
                lblZip.Text = dt.Rows[0]["stf_zip_pri"].ToString().Trim();
                lblSecnAdd1.Text = dt.Rows[0]["stf_addr1_mail"].ToString().Trim();
                lblSecnAdd2.Text = dt.Rows[0]["stf_addr2_mail"].ToString().Trim();
                lblSecnCity.Text = dt.Rows[0]["stf_city_mail"].ToString().Trim();
                lblSecnState.Text = dt.Rows[0]["mailstate"].ToString().Trim();
                lblSecnZip.Text = dt.Rows[0]["stf_zip_mail"].ToString().Trim();
                lblPObox.Text = dt.Rows[0]["stf_pobox_mail"].ToString().Trim();
                lblHomePhn.Text = dt.Rows[0]["stf_home_phn"].ToString().Trim();
                lblOffcPhn.Text = dt.Rows[0]["stf_offc_phn"].ToString().Trim();
                lblMobPhn.Text = dt.Rows[0]["stf_mobile_phn"].ToString().Trim();
                lblWrkEmail.Text = dt.Rows[0]["stf_wrk_email"].ToString().Trim();
                lblPersEmail.Text = dt.Rows[0]["stf_personal_email"].ToString().Trim();
                lblEmrgnFrstNam.Text = dt.Rows[0]["stf_emrgn_first_name"].ToString().Trim();
                lblEmrgnWrkPhn.Text = dt.Rows[0]["stf_emrgn_offc_phn"].ToString().Trim();
                lblEmrgnLastNam.Text = dt.Rows[0]["stf_emrgn_last_name"].ToString().Trim();
                lblEmrgnMobPhn.Text = dt.Rows[0]["stf_emrgn_mobile_phn"].ToString().Trim();
                lblEmrgnHomPhn.Text = dt.Rows[0]["stf_emrgn_home_phn"].ToString().Trim();
                lblEmrgnEmail.Text = dt.Rows[0]["stf_emrgn_email"].ToString().Trim();
                int relaid = Convert.ToInt32(dt.Rows[0]["stf_emrgn_relationship"].ToString().Trim());
                switch (relaid)
                {
                    case 1: lblRelation.Text = "Spouse";
                        break;
                    case 2: lblRelation.Text = "Mother";
                        break;
                    case 3: lblRelation.Text = "Father";
                        break;
                    case 4: lblRelation.Text = "Brother";
                        break;
                    case 5: lblRelation.Text = "Sister";
                        break;
                    case 6: lblRelation.Text = "Son";
                        break;
                    case 7: lblRelation.Text = "Daughter";
                        break;
                    case 8: lblRelation.Text = "Partner";
                        break;
                    case 9: lblRelation.Text = "Friend";
                        break;
                    case 10: lblRelation.Text = "Other";
                        break;
                }
                lblStaffTyp.Text = dt.Rows[0]["stafftype"].ToString().Trim();
                lblJobTitle.Text = dt.Rows[0]["stf_job_title"].ToString().Trim();
                if (dt.Rows[0]["stf_hire_dt"].ToString().Trim() != "")
                {
                    DateTime joindate = DateTime.Parse(dt.Rows[0]["stf_hire_dt"].ToString().Trim());
                    string JoiningDate = joindate.Date.ToString(SISinstall.CalenderDateFormat);
                    lbljoiningdat.Text = JoiningDate;
                }

                lblleftdate.Text = dt.Rows[0]["stf_term_dt"].ToString().Trim();
                lblSchools.Text = dt.Rows[0]["schoolname"].ToString().Trim();
                //lblOpenProf.Text = STABL.Role;
                if (dt.Rows[0]["stf_opensis_access"].ToString().Trim() == "N")
                {
                    pnlOpenAcces.Visible = false;
                }
                else
                {
                    pnlOpenAcces.Visible = true;
                }
                string id = dt.Rows[0]["school_access"].ToString().Trim();
                string[] b = id.Split(new char[] { ',' });
                string schoolaccess = "";
                for (int k = 0; k < b.Length; k++)
                {
                    if (b[k].Trim().ToLower() == "")
                    {
                        schoolaccess += "0";
                    }
                    else
                    {
                        schoolaccess += b[k] + ",";
                    }
                }
                //.Text = schoolaccess;                
                if (dt.Rows[0]["stf_opensis_access"].ToString().Trim() != "N")
                {
                    OpenSISWCFServiceStaffClient SPCClient2 = new OpenSISWCFServiceStaffClient();
                    DataTable dtschools = SPCClient2.PopulateSchoolaccesschkbox(schoolaccess);
                    SPCClient2.Close();
                    rptrSchools.DataSource = dtschools;
                    rptrSchools.DataBind();
                }
                switch (dt.Rows[0]["stf_opensis_access"].ToString().Trim())
                {
                    case "Y": lblOpensisAccess.Text = "Yes";
                        break;
                    case "N": lblOpensisAccess.Text = "No";
                        break;
                    case "": lblOpensisAccess.Text = "";
                        break;
                }
                //lblOpensisAccess.Text = dt.Rows[0]["stf_opensis_access"].ToString().Trim();
                lblStaUsrnam.Text = dt.Rows[0]["stf_user_nm"].ToString().Trim();
                lblStaPass.Text = dt.Rows[0]["stf_pwd"].ToString().Trim();
                if (dt.Rows[0]["stf_secret_ques"].ToString().Trim() != "")
                {
                    int quesid = Convert.ToInt32(dt.Rows[0]["stf_secret_ques"].ToString().Trim());
                    switch (quesid)
                    {
                        case 1: lblSecQues.Text = "What is your pet's name?";
                            break;
                        case 2: lblSecQues.Text = "What is your mother's maiden name?";
                            break;
                        case 3: lblSecQues.Text = "What is your favourite holiday destination?";
                            break;
                        case 4: lblSecQues.Text = "What is your favourite festival?";
                            break;
                        case 5: lblSecQues.Text = "Where did you meet your spouse ?";
                            break;
                        case 0: lblSecQues.Text = "";
                            break;
                    }
                }
                lblSecrAnsr.Text = dt.Rows[0]["stf_secret_ans"].ToString().Trim();
                if (dt.Rows[0]["stf_lib_access"].ToString().Trim() == "N")
                {
                    pnlLib.Visible = false;
                }
                else
                {
                    pnlLib.Visible = true;
                }
                switch (dt.Rows[0]["stf_lib_access"].ToString().Trim())
                {
                    case "Y": lblLibAcces.Text = "Yes";
                        break;
                    case "N": lblLibAcces.Text = "No";
                        break;
                    case "": lblLibAcces.Text = "";
                        break;
                }

                if (dt.Rows[0]["stf_lib_class"].ToString().Trim() != "")
                {
                    int libclasid = Convert.ToInt32(dt.Rows[0]["stf_lib_class"].ToString().Trim());
                    switch (libclasid)
                    {
                        case 1: lblLibCLass.Text = "All";
                            break;
                        case 2: lblLibCLass.Text = "Adult";
                            break;
                        case 3: lblLibCLass.Text = "Child";
                            break;
                        case 4: lblLibCLass.Text = "Adoloscent";
                            break;
                    }
                }
                lblLibCrdNo.Text = dt.Rows[0]["stf_lib_card_no"].ToString().Trim();
                if (dt.Rows[0]["stf_status"].ToString().Trim() != "")
                {
                    int statusid = Convert.ToInt32(dt.Rows[0]["stf_status"].ToString().Trim());
                    switch (statusid)
                    {
                        case 1: lblStatus.Text = "Active";
                            break;
                        case 2: lblStatus.Text = "Inactive";
                            break;
                    }
                }

                if (dt.Rows[0]["stf_dob"].ToString().Trim() != "")
                {
                    DateTime dob = DateTime.Parse(dt.Rows[0]["stf_dob"].ToString().Trim());
                    string DOB = dob.Date.ToString(SISinstall.CalenderDateFormat);
                    lblDOB.Text = DOB;
                }

                if (dt.Rows[0]["stf_hire_dt"].ToString().Trim() != "")
                {
                    DateTime joindate = DateTime.Parse(dt.Rows[0]["stf_hire_dt"].ToString().Trim());
                    string JoiningDate = joindate.Date.ToString(SISinstall.CalenderDateFormat);
                    lblDateJoin.Text = JoiningDate;
                }


                if (dt.Rows[0]["stf_term_dt"].ToString().Trim() != "")
                {
                    DateTime enddate = DateTime.Parse(dt.Rows[0]["stf_term_dt"].ToString().Trim());
                    lblleftdate.Text = enddate.Date.ToString(SISinstall.CalenderDateFormat);
                }
                else
                {
                    lblleftdate.Text = dt.Rows[0]["stf_term_dt"].ToString().Trim();
                }
                lblfullname.Text = lblSalutation.Text + " " + lblStaFrstNam.Text + " " + lblStaMidlNam.Text + " " + lblStalstNam.Text + " " + lblSuffix.Text;

                lblsummaryJobTitle.Text = dt.Rows[0]["stf_job_title"].ToString().Trim();                
                lblsummaryHomeSchool.Text = dt.Rows[0]["schoolname"].ToString().Trim();
                lblsummaryStaffid.Text = dt.Rows[0]["staffidnumber"].ToString().Trim();
                lblsummaryemail.Text = dt.Rows[0]["stf_wrk_email"].ToString().Trim();
                lblsummaryofficephn.Text = dt.Rows[0]["stf_offc_phn"].ToString().Trim();
                lblsummarymobphn.Text = dt.Rows[0]["stf_mobile_phn"].ToString().Trim();
                lblJobcat.Text = dt.Rows[0]["stafftype"].ToString().Trim();

                if (dt.Rows[0]["stf_hire_dt"].ToString().Trim() != "")
                {
                    DateTime joindate = DateTime.Parse(dt.Rows[0]["stf_hire_dt"].ToString().Trim());
                    string JoiningDate = joindate.Date.ToString(SISinstall.CalenderDateFormat);
                    lbljoiningdat.Text = JoiningDate;
                }               

                OpenSISWCFServiceStaffClient SPCClient3 = new OpenSISWCFServiceStaffClient();
                DataTable dtcert = SPCClient3.PopulateCertification(StaffId);
                SPCClient3.Close();
                if (dtcert.Rows.Count > 0)
                {
                    gvCertficates.DataSource = dtcert;
                    gvCertficates.DataBind();
                }
                else
                {
                    DataTable dtcertblnk = new DataTable();
                    dtcertblnk.Columns.Add("stf_id");
                    dtcertblnk.Columns.Add("stf_cert_dt");
                    dtcertblnk.Columns.Add("stf_cert_exp_dt");
                    dtcertblnk.Columns.Add("stf_cert_cd");
                    dtcertblnk.Columns.Add("stf_cert_short_nm");
                    dtcertblnk.Columns.Add("stf_cert_nm");
                    dtcertblnk.Columns.Add("stf_pri_cert_ind");
                    dtcertblnk.Columns.Add("stf_cert_desc");
                    DataRow dr = dtcertblnk.NewRow();
                    dr["stf_id"] = StaffId;
                    dr["stf_cert_dt"] = "";
                    dr["stf_cert_exp_dt"] = "";
                    dr["stf_cert_cd"] = "";
                    dr["stf_cert_short_nm"] = "";
                    dr["stf_cert_nm"] = "";
                    dr["stf_pri_cert_ind"] = "";
                    dr["stf_cert_desc"] = "";
                    dtcertblnk.Rows.Add(dr);
                    gvCertficates.DataSource = dtcertblnk;
                    gvCertficates.DataBind();
                }

                OpenSISWCFServiceStaffClient SPCClient4 = new OpenSISWCFServiceStaffClient();
                DataTable dtpic = SPCClient4.PopulatestaffPhoto(StaffId, Convert.ToInt32(dt.Rows[0]["sch_id"]));
                if (dtpic.Rows.Count > 0)
                {
                    string PhotoUrl = dtpic.Rows[0]["name"].ToString();
                    if (PhotoUrl != "")
                    {
                        divPhoto.Style.Add("background-image", "url(" + PhotoUrl + ")");
                    }
                }
                else
                {
                    divPhoto.Style.Add("background-image", "url(../App_Themes/main/images/no_pic.png)");
                }
            }
            catch
            {
            }
            finally
            {

            }
        }

        protected void gvCertficates_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            SISInstall SISinstall = new SISInstall();
            //StaffBL STABL = new StaffBL();
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblCertDate = (Label)e.Row.FindControl("lblCertDate");
                Label lblCertExpDate = (Label)e.Row.FindControl("lblCertExpDate");
                Label lblPrimryCert = (Label)e.Row.FindControl("lblPrimryCert");
                if (lblCertDate.Text != "")
                {
                    DateTime certdate = DateTime.Parse(lblCertDate.Text);
                    lblCertDate.Text = certdate.Date.ToString(SISinstall.CalenderDateFormat);
                }
                if (lblCertExpDate.Text != "")
                {
                    DateTime CertExpDate = DateTime.Parse(lblCertExpDate.Text);
                    lblCertExpDate.Text = CertExpDate.Date.ToString(SISinstall.CalenderDateFormat);
                }
                //if (STABL.Primarycert.Trim() == "Y")
                //{
                //    lblPrimryCert.Text = "Yes";
                //}
                //if (STABL.Primarycert.Trim() == "N")
                //{
                //    lblPrimryCert.Text = "No";
                //}
            }
        }

        protected void ibtnEdit_Click(object sender, ImageClickEventArgs e)
        {
            //StaffBL STABL = new StaffBL();
            for (int i = 0; i < gvStaff.Rows.Count; i++)
            {
                CheckBox chk = (CheckBox)gvStaff.Rows[i].FindControl("chkrow");
                HiddenField hdnstfid = (HiddenField)gvStaff.Rows[i].FindControl("hdnstfidg");
                if (chk.Checked)
                {
                    Session["StaffId"] = hdnstfid.Value.ToString();
                    Response.Redirect("EditStaffInfo.aspx");
                }
            }
        }

        protected void ibtnView_Click(object sender, ImageClickEventArgs e)
        {
            for (int i = 0; i < gvStaff.Rows.Count; i++)
            {
                CheckBox chk = (CheckBox)gvStaff.Rows[i].FindControl("chkrow");
                HiddenField hdnstfid = (HiddenField)gvStaff.Rows[i].FindControl("hdnstfidg");


                if (chk.Checked)
                {
                    //string staffid = hdnstfid.Value.ToString();
                    //hdnStfId.Value = staffid;
                    //int StaffId = Convert.ToInt32(hdnStfId.Value);                    
                    //int SchoolId = Convert.ToInt32(Session["SchoolID"]);
                    Session["StaffID"] = hdnstfid.Value;
                    PopulateStaffDetails();
                    tvCategories.Nodes[0].Select();
                    lblCatName.Text = "<div class='heading_bevelline'>" + tvCategories.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";

                    lblStaffNo.Text = (i + 1).ToString();
                    lblTotalStaffOfSchool.Text = (gvStaff.Rows.Count).ToString();
                    if (lblStaffNo.Text == lblTotalStaffOfSchool.Text)
                    {
                        lbtnLastStaff.Enabled = false;
                        lbtnNextStaff.Enabled = false;
                    }
                    if (lblStaffNo.Text == "1")
                    {
                        lbtnPreviousStaff.Enabled = false;
                        lbtnFirstStaff.Enabled = false;
                    }
                    mvMain.ActiveViewIndex = 1;
                }
            }
        }

        private void ml_InitCulture()
        {
            if (Session["MLCulture"] != null && Session["MLUICulture"] != null)
            {
                String MLCultureName = (String)Session["MLCulture"];
                //sCulture = Session["MLCulture"].ToString();
                String MLUICultureName = (String)Session["MLUICulture"];

                if ((MLCultureName != null) && (MLCultureName.Length > 0))
                {
                    Page.Culture = MLCultureName;
                }

                if ((MLUICultureName != null) && (MLUICultureName.Length > 0))
                {
                    Page.UICulture = MLUICultureName;
                }
            }
        }

        protected override void InitializeCulture()
        {
            ml_InitCulture();
        }
    }
}